/**
 * 
 */
package com.mevoy.async.dao.couchdb;

import org.jcouchdb.db.Database;

import com.mevoy.async.dao.UserReportDao;
import com.mevoy.async.dao.exception.ReportAccessException;

/**
 * @author diegoicosta
 * 
 */
public class UserReportDaoImpl implements UserReportDao<UserReportCouchImpl> {

	private CouchDBConnection couchConnection;
	private Database db;

	public void setCouchConnection(CouchDBConnection couchConnection) {
		this.couchConnection = couchConnection;
		db = couchConnection.getCouchDB();
	}

	public UserReportCouchImpl saveReport(UserReportCouchImpl userReport)
			throws ReportAccessException {
		db.createDocument(userReport);
		return userReport;
	}

	public UserReportCouchImpl getReportById(int reportId)
			throws ReportAccessException {
		return db.getDocument(UserReportCouchImpl.class, String
				.valueOf(reportId));
	}

	public void deleteReport(UserReportCouchImpl userReport)
			throws ReportAccessException {
		db.delete(userReport);
	}
}
